﻿

using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using COM.Rights.Model;



namespace COM.Rights.BLL
{   
    public partial class TRoleTTTOU 
    {

        public List<TRoleTTTOUInfo> GetRolesByOU(string ouGID)
        {
            List<TRoleTTTOUInfo> infos = new List<TRoleTTTOUInfo>();
            string filter = "TOU_GID=@TOU_GID";
            List<DBParameter> dps = new List<DBParameter>();
            dps.Add(new DBParameter("TOU_GID", ouGID));       
            infos = GetList("", filter, "", dps);

            return infos;
        }

        public string GetRoleIDSByOU(string ouGID)
        {
            string ids = "";

            List<TRoleTTTOUInfo> infos = GetRolesByOU(ouGID);

            foreach (TRoleTTTOUInfo info in infos)
            {
                ids += info.TRole_GID + ",";
            }
            return ids.Trim(',');
        }

        public bool SaveRols(string ouGID, string roleIDS)
        {
            string ids = roleIDS.Trim(',');

            List<TRoleTTTOUInfo> infos = new List<TRoleTTTOUInfo>();

            foreach (string s in ids.Split(','))
            {
                if (!string.IsNullOrEmpty(s))
                {
                    TRoleTTTOUInfo info = new TRoleTTTOUInfo();
                    info.TRole_GID = s;
                    info.TOU_GID = ouGID;
                    infos.Add(info);
                }
            }

            string filter = "TOU_GID=@ouGID";
            List<DBParameter> dps = new List<DBParameter>();
            dps.Add(new DBParameter("ouGID", ouGID));
            this.Delete(filter, dps);
            this.Add(infos, "");
            return true;
        }

        partial void OnBLLCreated() { ConfigName = "Rights"; }

	}
}